Appendix 2F: OpenBUGS code for the multi-year time-trend site-occupancy model 

This is similar to the unconstrained site-occupancy model, but the pattern in abundance over space
and time is constrained by having a fitted year effect (time trend) and a random transect effect.

Model {

	# Detection model
	a.p ~ dnorm(0,1)		# logit of average detection probability
	s.j.p ~ dunif(0,1)     	 	# SD among surveys in logit p 
	tau.j.p <- pow(s.j.p,-2)   	# convert to precision

	for (j in 1:n.surveys) { 	# for each survey...
		re.j.p[j] ~ dnorm(0, tau.j.p)	# assign nightly random effect on detection prob.
		logit(p[j]) <- a.p+re.j.p[j]	# calc. prob of of 1+ frog being detected if segment occupied
	}

	# Occupancy model
	a.N ~ dnorm(0,1)		# prior for expected value of log(N) for average transect in 2012
	b.year ~ dnorm(0,1) 		# average annual change in log(N)
	s.trans.N ~ dunif(0,5)		# SD in log N among transects
	tau.trans.N <-pow(s.trans.N,-2)	# convert to precision

	for (i in 1:n.transects) {		# for each transect... 
		re.trans.N[i] ~ dnorm(0, tau.trans.N)	# assign random effect on log(N)
	}

	for (i in 1:n.transect.years) { 	# for each transect for each year...
		log(mu[i]) <- a.N + b.year*(year[i]-2012) + re.trans.N[transect[i]]	# calculate expected N
		N[i] ~ dpois(mu[i])			# sample actual of N from expected value for N																# sample N from expected
		p.present[i] <- 1-exp(-N[i]/10)		# prob. of any 10m segment on the transect being occupied
	}

	for (i in 1:n.segments) {   	# for each 10-m segment of each transect in each survey...
		present[i]~ dbern(p.present[transect.year[i]])	# sample occupancy of segment based on pr. occupancy
		for (j in 1:n.surveys) {			# for each survey of segment...
			p.detect[i,j] <- present[i]*p[j]		# prob. of 1+ frogs being seen on segment in survey j
			detected[i,j] ~ dbern(p.detect[i,j]) 		# sample whether frog(s) detected based on p.seen
		}
	}	
	
	# Derived parameters 
	lambda <- exp(b.year)		# proportional annual change in abundance 
	lambda9 <- pow(lambda,9)	# change in abdundance over 9 year timeframe 
}